from celery_tasks.celery import app
from ihome_01.libs.qiniuyun.qiniu_storage import storage
from ihome_01.utils import constants


@app.task(bind=True)
def upload_image(self,file_data):
    # 测试耗时
    # import time
    # time.sleep(10)

    # 1, 发送短信
    try:
        result = storage(file_data)
    except Exception as e:
        result = -1

    # 2,判断是否发送成功
    if result == -1:
        # 重试, exc: 发送短信失败报的异常,  countdown: 间隔几秒重试, max_retries:重试的次数
        self.retry(exc=Exception("上传图片失败"), countdown=5, max_retries=3)

    return result
